# Recreate the webpage image with a font that supports Chinese characters

from PIL import Image, ImageDraw, ImageFont
import matplotlib.pyplot as plt
import os
import urllib.request

# 设置matplotlib中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False


# 获取或下载中文字体
def get_chinese_font():
    font_paths = [
        "C:/Windows/Fonts/SimHei.ttf",  # Windows
        "SourceHanSansSC-Regular.otf"  # 下载的字体
    ]

    for path in font_paths:
        if os.path.exists(path):
            return path

    # 如果没有找到字体，下载一个
    font_url = "https://github.com/adobe-fonts/source-han-sans/raw/release/OTF/SourceHanSansSC-Regular.otf"
    urllib.request.urlretrieve(font_url, "SourceHanSansSC-Regular.otf")
    return "SourceHanSansSC-Regular.otf"


# 获取字体路径
font_path = get_chinese_font()

# 创建字体对象
title_font = ImageFont.truetype(font_path, 40)
subtitle_font = ImageFont.truetype(font_path, 30)
body_font = ImageFont.truetype(font_path, 25)

# Create a blank webpage-style image
image_width, image_height = 1000, 1500
background_color = "white"
text_color = "black"

# Initialize image and drawing context
webpage = Image.new("RGB", (image_width, image_height), background_color)
draw = ImageDraw.Draw(webpage)

# Draw title and subtitles
margin = 50
current_height = margin

draw.text((margin, current_height), "不同岗位薪资与学历要求分析报告", font=title_font, fill=text_color)
current_height += 60

draw.text((margin, current_height), "一、不同薪资水平的岗位数量分布", font=subtitle_font, fill=text_color)
current_height += 40

paragraph = (
    "根据图表“不同薪资水平的岗位数量柱状图”，我们可以清晰地看到不同薪资范围内岗位数量的分布情况。从数据上来看：\n\n"
    "- 2000元以下和4000元以下的岗位数量仅为1，显然这些低薪岗位在市场中的需求较少。\n"
    "- 8000元至10000元的岗位需求量上升至4，薪资区间中需求有明显增幅。\n"
    "- 10000元以上的岗位需求数量最高，达到6，反映出高薪岗位在市场中的竞争力和吸引力。\n"
    "- 14000元以上的岗位数量又回落至1，可能表明超高薪岗位较为稀缺。\n"
)
draw.text((margin, current_height), paragraph, font=body_font, fill=text_color)
current_height += 200

# Add bar chart
bar_chart = Image.open("3.png")
bar_chart = bar_chart.resize((800, 400))
webpage.paste(bar_chart, (margin, current_height))
current_height += 420

draw.text((margin, current_height), "二、不同学历要求的岗位数量分布", font=subtitle_font, fill=text_color)
current_height += 40

paragraph = (
    "通过“不同学历要求的岗位数量饼状图”，我们可以进一步了解到市场对学历的需求情况：\n\n"
    "- 本科岗位数量占比60%，显然本科已成为企业招聘的主要学历门槛。\n"
    "- 大专岗位数量占比40%，表明市场仍为技能型人才预留了大量机会。\n"
)
draw.text((margin, current_height), paragraph, font=body_font, fill=text_color)
current_height += 200

# Add pie chart
pie_chart = Image.open("4.png")
pie_chart = pie_chart.resize((800, 400))
webpage.paste(pie_chart, (margin, current_height))
current_height += 420

draw.text((margin, current_height), "三、分析与趋势", font=subtitle_font, fill=text_color)
current_height += 40

paragraph = (
    "从数据分析中可以推测出以下几点趋势：\n\n"
    "1. 高薪岗位更受关注：企业在招揽高端人才时可能愿意支付更高的薪酬，市场逐步向高薪岗位倾斜。\n"
    "2. 本科成为主流学历要求：绝大多数企业将本科视为基本学历标准，竞争力更高。\n"
    "3. 技能型人才仍具市场空间：大专学历在部分岗位中依然占据了40%的比例，技能型人才需求强劲。\n\n"
    "未来的人才市场中，如何提升自身学历和技能，抓住高薪岗位的机遇，将成为求职者的重要目标。"
)
draw.text((margin, current_height), paragraph, font=body_font, fill=text_color)

# Save the generated webpage image
webpage_path = "news_webpage_chinese.png"
webpage.save(webpage_path)
webpage_path
